/**
 * 获取存储的数据
 * @param {string} key
 */

export const getItem = key => {
  const data = localStorage.getItem(key)
  try {
    return JSON.parse(data)
  } catch (e) {
    return data
  }
}

/**
 * 存储数据
 * @param {string} key
 * @param {*} data
 */

export const setItem = (key, data) => {
  if (typeof data === 'object') {
    data = JSON.stringify(data)
  }
  localStorage.setItem(key, data)
}

/**
 *删除存储的数据
 * @param {string} key
 */
export const removeItem = key => {
  localStorage.removeItem(key)
}
